
// g++ main.cpp -ldl

#include <iostream>
#include "dylib.hpp"

std::unique_ptr<dylib> lib;

int main()
{
    try
    {
        lib = std::make_unique<dylib>(".", "dynamic_lib");

        auto adder = lib->get_function<double(double, double)>("adder");
        std::cout << adder(5, 10) << std::endl;

        auto printer = lib->get_function<void()>("print_hello");
        printer();

        double pi_value = lib->get_variable<double>("pi_value");
        std::cout << pi_value << std::endl;

        void* ptr = lib->get_variable<void*>("ptr");
        if (ptr == (void*)1)
            std::cout << 1 << std::endl;
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }

    lib.reset();

    return EXIT_SUCCESS;
}